home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
ACORNUSERS
/
EMULATOR
/
EMUL6502
/
Sources
/
Squares
< prev
next >
Wrap
Text File
|
1998-08-27
|
3KB
|
103 lines
;Alain BROBECKER (aka baah/Arm's Tech), 23aug1998
;
;This program was written to test the good functioning of a 6502 emulator.
;It works just fine with 'emul6502' and i tried to have as many opcodes or
;adressing modes as possible, so no optimisations out there.
;What it does is...
; -- Computes squares of [0..127] with 2 methods and store them in memory.
; Of course the results are normally the same.
; -- Use 2 methods to compare the results. If first method find difference
; it jumps at adress 0 (should contain &00=opcode for 'brk'), and if
; second method find differences it jumps at adress 1. If no problem
; occured (or your emulator is unable to do the comparisons =) it shall
; end with the 'brk' inside the code.
#name SquaresX
#list
#base &100-4 ;Start assembly here
#rw &100 ;Load adress
#rw &100 ;Exec adress
;Zero page adresses used as storage
#set mul1 = &10
#set mul2 = &11
#set sqr1 = &10
#set sqr2 = &12
;compute squares with succesive iterations... (n+1)²=n²+2n+1
ldx #0 ;counter=2n
.sqr1_one
txa:clc:adc #1 ;a=2*n+1, and C=0, since 0<n<127
adc squares,x ;current+=2n+1
sta squares+2,x
lda squares+1,x
adc #0
sta squares+3,x
inx:inx ;x+=2
cpx #254:bne sqr1_one
;compute squares with brutal shift multiplication...
ldy #0 ;counter=n
.sqr2_one
lda #0 ;initialise result and high(mul2)
sta z,mul2+1
sta squares+256,y
sta squares+257,y
tya:lsr ;a=n
sta z,mul1 ;save n into multiplicands
sta z,mul2
.sqr2_shift_one
lsr z,mul1 ;put lower bit in carry
bcc sqr2_next_shift ;no addition when carry=0
clc
lda z,mul2 ;16 bits addition
adc squares+256,y
sta squares+256,y
lda z,mul2+1
adc squares+257,y
sta squares+257,y
.sqr2_next_shift
asl z,mul2 ;rotate rw in mul2
rol z,mul2+1
lda z,mul1
bne sqr2_shift_one ;quit when z,mul1=0
iny:iny ;y+=2
bne sqr2_one
;first comparison method, quite stupid
ldx #0
.cmp1_one
dex
beq cmp1_ok
lda squares,x
cmp squares+256,x
beq cmp1_one
jmp 0
.cmp1_ok
;second method, uses post-indexed indirect adressing and sbc
lda #squares AND &ff ;save adresses in zeropage
sta z,sqr1
lda #squares>>8
sta z,sqr1+1
ldx #(squares+256)AND &ff
stx z,sqr2
ldy #(squares+256)>>8
sty z,sqr2+1
ldy #0
.cmp2_one
dey
beq cmp2_ok
lda (sqr1),y ;a=byte pointed by adress at sqr1
sec
sbc (sqr2),y
beq cmp2_one
jmp 1
.cmp2_ok
brk
.temp
#rw 0
.squares
#rw 0